package com.tancire.member.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.member.domain.MemberTrainProblem;
import com.tancire.member.service.IMemberTrainProblemService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 会员错题本Controller
 *
 * @author tancire
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/member/memberTrainProblem")
public class MemberTrainProblemController extends BaseController {
    @Resource
    private IMemberTrainProblemService memberTrainProblemService;

    /**
     * 查询会员错题本列表
     */
    @PreAuthorize("@ss.hasPermi('member:memberTrainProblem:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberTrainProblem memberTrainProblem) {
        startPage();
        List<MemberTrainProblem> list = memberTrainProblemService.selectList(memberTrainProblem);
        return getDataTable(list);
    }

    /**
     * 导出会员错题本列表
     */
    @PreAuthorize("@ss.hasPermi('member:memberTrainProblem:export')")
    @Log(title = "会员错题本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberTrainProblem memberTrainProblem) {
        List<MemberTrainProblem> list = memberTrainProblemService.selectMemberTrainProblemList(memberTrainProblem);
        ExcelUtil<MemberTrainProblem> util = new ExcelUtil<MemberTrainProblem>(MemberTrainProblem.class);
        util.exportExcel(response, list, "会员错题本数据");
    }

    /**
     * 获取会员错题本详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:memberTrainProblem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(memberTrainProblemService.selectMemberTrainProblemById(id));
    }

    /**
     * 新增会员错题本
     */
    @PreAuthorize("@ss.hasPermi('member:memberTrainProblem:add')")
    @Log(title = "会员错题本", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberTrainProblem memberTrainProblem) {
        return toAjax(memberTrainProblemService.insertMemberTrainProblem(memberTrainProblem));
    }

    /**
     * 修改会员错题本
     */
    @PreAuthorize("@ss.hasPermi('member:memberTrainProblem:edit')")
    @Log(title = "会员错题本", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberTrainProblem memberTrainProblem) {
        return toAjax(memberTrainProblemService.updateMemberTrainProblem(memberTrainProblem));
    }

    /**
     * 删除会员错题本
     */
    @PreAuthorize("@ss.hasPermi('member:memberTrainProblem:remove')")
    @Log(title = "会员错题本", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(memberTrainProblemService.deleteMemberTrainProblemByIds(ids));
    }
}
